1 module tools.releasegame; 2 3 import commons; 4 import std.string; 5 import std.array; 6 import std.path; 7 import std.file; 8 9 enum string[] availableSourceFolders = ["source", "src", "scripts"]; 10 enum string[] ignoreExtensions = [".dll", ".lib", ".so", ".obj", ".pdb", ".gitkeep"]; 11 enum string[] ignoreFolders = [".dub", ".git", ".history"]; 12 13 14 string[] getGameValidFiles(string input) 15 { 16 string[] validFiles; 17 FileLoop: foreach(DirEntry e; dirEntries(input, SpanMode.shallow)) 18 { 19 foreach(folder; ignoreFolders) 20 { 21 if(e.name.indexOf(folder) != -1) 22 continue FileLoop; 23 } 24 validFiles~= e.name; 25 } 26 return validFiles; 27 } 28 29 bool shouldFileSkip(string fileName) 30 { 31 string ext = fileName.extension; 32 33 foreach(x; ignoreExtensions) 34 { 35 if(ext.indexOf(x) != -1) 36 return true; 37 } 38 return false; 39 } 40 41 string outputPath = "release_game"; 42 43 44 void releaseGame(ref Terminal t, string gamePath, string outputFolder, bool verbose) 45 { 46 t.writeln("Creating directory: ", outputFolder); 47 mkdirRecurse(outputFolder); 48 49 string[] validFiles = getGameValidFiles(gamePath); 50 foreach(f; validFiles) 51 { 52 if(isDir(f)) 53 { 54 t.writeln("Copying contents from folder ", f); 55 foreach(DirEntry e; dirEntries(f, SpanMode.breadth)) 56 { 57 string relativizedName = relativePath(e.name, gamePath); 58 string outputBasedOnGame = buildNormalizedPath(outputFolder, relativizedName); 59 if(isDir(e.name)) 60 { 61 if(!exists(outputBasedOnGame)) 62 { 63 if(verbose) 64 t.writeln("[FOLDER_CONTENT] MKDIR ",outputBasedOnGame); 65 mkdirRecurse(outputBasedOnGame); 66 } 67 } 68 else 69 { 70 if(!exists(dirName(outputBasedOnGame))) 71 { 72 if(verbose) 73 t.writeln("[FOLDER_CONTENT] MKDIR ",outputBasedOnGame); 74 mkdirRecurse(dirName(outputBasedOnGame)); 75 } 76 if(verbose) 77 t.writeln("[FOLDER_CONTENT] COPY[",e.name,"] ---> ", outputBasedOnGame); 78 copy(e.name, outputBasedOnGame); 79 } 80 } 81 } 82 else if(!shouldFileSkip(f)) 83 { 84 string relativizedName = relativePath(f, gamePath); 85 string outputBasedOnGame = buildPath(outputFolder, relativizedName); 86 if(verbose) 87 t.writeln("Copying [",f,"] -> ", outputBasedOnGame); 88 copy(f, outputBasedOnGame); 89 } 90 } 91 }